<script setup lang="ts">
import { useRenderIcon } from '@/components/ReIcon/src/hooks'

import { useTableHeight } from '@/hooks/useTableHeight'
import Refresh from '@iconify-icons/ep/refresh'
import Search from '@iconify-icons/ep/search'
import { useRouter } from 'vue-router'
import useList from './useList'

const router = useRouter()

defineOptions({
  name: 'api-manage/list',
})

const {
  isLoading,
  formRef,
  columns,
  queryParams,
  pagination,
  dataList,
  changePageNumber,
  changePageSize,
  resetForm,
  onSearch,
  onExport,
  onRowSelectionChange,
} = useList()
const { tableHeight, tableRef } = useTableHeight()

onSearch()
</script>

<template>
  <div class="main table-view-layout">
    <el-form
      ref="formRef"
      :inline="true"
      :model="queryParams"
      class="bg-el-bg w-[99/100] pl-8 pt-4"
    >
      <el-form-item prop="name">
        <el-input
          v-model="queryParams.apiName"
          placeholder="请输入接口名称关键词"
          clearable
          style="width: 240px"
          @keyup.enter="onSearch"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon(Search)"
          :loading="isLoading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm"> 重置 </el-button>
      </el-form-item>
    </el-form>
    <PureTableBar title="接口服务列表">
      <template #buttons>
        <el-button
          type="primary"
          @click="
            () => {
              queryParams.checkStatus = 1
              onExport()
              queryParams.checkStatus = null
            }
          "
          >导出数据</el-button
        >
      </template>
      <template #table>
        <pure-table
          ref="tableRef"
          border
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="isLoading"
          :max-height="tableHeight"
          :data="dataList"
          :columns="columns"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)',
          }"
          :pagination="pagination"
          @page-size-change="changePageSize"
          @page-current-change="changePageNumber"
          @selection-change="onRowSelectionChange"
        >
          <template #operation="{ row }">
            <el-button
              link
              class="reset-margin"
              type="primary"
              @click="
                router.push({
                  path: '/api-manage/detail',
                  query: { id: row.id },
                })
              "
            >
              接口详情
            </el-button>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
